package com.leetcode.题库.score1;

import java.util.Scanner;

/**
 * @BelongsProject: LeetCode
 * @BelongsPackage: com.leetcode.题库.score1
 * @Author: lei
 * @CreateTime: 2024-03-12  17:46
 * @Description: 给你一个字符串s, 首尾相连成一个环形，
 * 请你在环中找出o字符出现了偶数次最长子字符串的长度
 * @Version: 1.0
 */
public class 环中最长子串 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()) {
            String s = scanner.nextLine();
            int length = s.length();
            int left = 0, right = 0, index = 0;
            if (!s.contains("o")) {
                System.out.println(s.length());
                break;
            }
            int result = 0;
            for (int i = 0; i < s.length(); i++) {
                int temp = i;
                String lStr = String.valueOf(s.charAt(i));
                // 获取第一个o元素的位置，标记为left和right的起点
                if (lStr.equalsIgnoreCase("o")) {
                    left = i;
                    right = i + 1;
                    index += 1;
                    while (right < (length + left)) {
                        right = right < length ? right : (length - right);
                        String str = String.valueOf(s.charAt(right));
                        if (str.equalsIgnoreCase("o")) {
                            index += 1;
                            if (index % 2 != 0) {
                                if (right < left) {
                                    temp = Math.max((length - left + right), temp);
                                } else {
                                    temp = Math.max(right - 1, temp);
                                }
                            }
                        }
                        right += 1;
                        if (left == right) break;
                    }
                }
                result = Math.max(temp, result);
                index = 0;
            }
            System.out.println(result);
        }
    }
}

